﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Copad.BusinessCard.DAL;
using Copad.BusinessCard.Model;

namespace Copad.BusinessCard.BLL
{
    public class CardPermissionsBLL
    {
        DataBase dataBase = new DataBase();

        public void UpdatePermissions(long cardID, List<long> userID, List<long> groupID)
        {
            dataBase.BeginTransaction();
            dataBase.Delete<CardGroupPermissions>(x => x.CardID == cardID);
            groupID.ForEach(x =>
            {
                CardGroupPermissions permissions = new CardGroupPermissions { CardID = cardID, GroupID = x };
                dataBase.Insert(permissions);
            });
            dataBase.Delete<CardUserPermissions>(x => x.CardID == cardID);
            userID.ForEach(x =>
            {
                CardUserPermissions permissions = new CardUserPermissions { CardID = cardID, UserID = x };
                dataBase.Insert(permissions);
            });
            dataBase.EndTransaction();
        }
    }
}
